import win32api
import win32con
import win32gui
from PyQt5.QtWinExtras import QtWin
from qframelesswindow.utils.win32_utils import findWindow


def is_maximized(h_wnd):
    """
    窗口是否最大化
    :param h_wnd: int or `sip.voidptr`
                window handle
    :return: 
    """
    window_placement = win32gui.GetWindowPlacement(h_wnd)
    if not window_placement:
        return False

    return window_placement[1] == win32con.SW_MAXIMIZE


def get_resize_border_thickness(h_wnd):
    """
    获取窗口调整大小的边框厚度
    :param h_wnd: int or `sip.voidptr`
    :return:
    """
    window = findWindow(h_wnd)
    if not window:
        return 0

    result = win32api.GetSystemMetrics(win32con.SM_CXSIZEFRAME) + win32api.GetSystemMetrics(92)

    if result > 0:
        return result

    thickness = 8 if QtWin.isCompositionEnabled() else 4
    return round(thickness * window.devicePixelRatio())
